home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_kdelibs.idb / usr / freeware / kde / include / kpixmap.h.z / kpixmap.h
Encoding:
C/C++ Source or Header  |  1999-01-26  |  6.7 KB  |  192 lines

  1. /* This file is part of the KDE libraries
  2.     Copyright (C) 1998    Mark Donohoe <donohoe@kde.org>
  3.                         Stephan Kulow                  
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public License
  16.     along with this library; see the file COPYING.LIB.  If not, write to
  17.     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  18.     Boston, MA 02111-1307, USA.
  19. */
  20.  
  21. #ifndef __KPIXMAP_H__
  22. #define __KPIXMAP_H__
  23.  
  24. #include <qpixmap.h>
  25.  
  26. const int KColorMode_Mask    = 0x00000300;
  27. const int WebOnly     = 0x00000200;
  28. const int LowOnly    = 0x00000300;
  29.  
  30. /**
  31.  * The KPixmap class is an off-screen buffer paint device that extends the
  32.  * features of QPixmap.
  33.  * 
  34.  * KPixmap has two new color modes, WebColor and LowColor, applicable to 8bpp
  35.  * displays.
  36.  *
  37.  * In WebColor mode all images are dithered to the Netscape palette, even when
  38.  * they have their own color table. WebColor is the default mode for KPixmap so
  39.  * that standard applications can share the Netscape palette across the desktop.
  40.  *
  41.  * In LowColor mode images are checked to see if their color table matches the
  42.  * KDE icon palette. If the color tables do not match, the images are dithered
  43.  * to a minimal 3x3x3 color cube. LowColor mode can be used to load icons,
  44.  * background images etc. so that components of the desktop which are always
  45.  * present use no more than 40 colors.
  46.  *
  47.  */
  48. class KPixmap : public QPixmap
  49. {
  50. public:
  51.     enum ColorMode { Auto, Color, Mono, LowColor, WebColor };
  52.     
  53.     /**
  54.      * Creates a null pixmap
  55.      */
  56.     KPixmap() {};
  57.     
  58.     /**
  59.      * Destroys the pixmap.
  60.      */
  61.     ~KPixmap() {};
  62.     
  63.     /**
  64.      * Fills the pixmap with a color blend running from color ca to color cb.
  65.      *
  66.      * If upDown is TRUE the blend will run from the top to the bottom of the
  67.      * pixmap. If upDown is FALSE the blend will run from the right to the left
  68.      * of the pixmap.
  69.      *
  70.      * By default, the blend will use 3 colors on 8 bpp displays,
  71.      * 32 colors on 16 bpp displays and unlimited colors at higher dislay
  72.      * depths. For 8bpp displays ncols specifies an alternative number of colors
  73.      * to use. The greater the number of colors allocated the better the
  74.      * appearance of the gradient but the longer it takes to make. 
  75.      */
  76.     void gradientFill( QColor ca, QColor cb, bool upDown = TRUE, int ncols = 3 );
  77.     
  78.     /**
  79.      * Fills the pixmap with a two color pattern, specified by the pattern bits
  80.      * in pattern[], the color ca to be used for the background and the color cb
  81.      * to be used for the foreground.
  82.      */
  83.     void patternFill( QColor ca, QColor cb, uint pattern[8] );
  84.     
  85.     /** 
  86.      * Converts an image and sets this pixmap. Returns TRUE if
  87.      * successful. 
  88.      *
  89.      * The conversion_flags argument is a bitwise-OR from the
  90.      * following choices. The options marked (default) are the
  91.      * choice if no other choice from the list is included (they
  92.      * are zero):
  93.      *
  94.      * Color/Mono preference
  95.      *
  96.      * <itemize>
  97.      * <item>WebColor -  If the image has depth 1 and contains
  98.      * only black and white pixels then the pixmap becomes monochrome. If
  99.      * the pixmap has a depth of 8 bits per pixel then the Netscape
  100.      * palette is used for the pixmap color table.
  101.      * <item>LowColor - If the image has depth 1 and contains only black and
  102.      * white pixels then the pixmap becomes monochrome. If the pixmap has a
  103.      * depth of 8 bits per pixel and the image does not posess a color table
  104.      * that matches the Icon palette a 3x3x3 color cube is used for the
  105.      * pixmap color table.
  106.      * <item>AutoColor (default) - If the image has depth 1 and contains
  107.      * only black and white pixels, then the pixmap becomes
  108.      * monochrome.
  109.      * <item>ColorOnly - The pixmap is dithered/converted to the native
  110.      * display depth.
  111.      * <item>MonoOnly - The pixmap becomes monochrome. If necessary, it
  112.      * is dithered using the chosen dithering algorithm.
  113.      * </itemize>
  114.      *
  115.      * Dithering mode preference, for RGB channels
  116.      *
  117.      * <itemize>
  118.      * <item>DiffuseDither (default) - a high quality dither
  119.      * <item>OrderedDither - a faster more ordered dither
  120.      * <item>ThresholdDither - no dithering, closest color is used
  121.      * </itemize>
  122.      *
  123.      * Dithering mode preference, for alpha channel
  124.      *
  125.      * <itemize>
  126.      * <item>DiffuseAlphaDither - a high quality dither
  127.      * <item>OrderedAlphaDither - a faster more ordered dither
  128.      * <item>ThresholdAlphaDither (default) - no dithering
  129.      * </itemize>
  130.      *
  131.      * Color matching versus dithering preference
  132.      * 
  133.      * <itemize>
  134.      * <item>PreferDither - always dither 32-bit images when the image
  135.      * is being converted to 8-bits. This is the default when
  136.      * converting to a pixmap.
  137.      * <item>AvoidDither - only dither 32-bit images if the image has
  138.      * more than 256 colours and it is being converted to 8-bits.
  139.      * This is the default when an image is converted for the
  140.      * purpose of saving to a file.
  141.      * </itemize>
  142.      *
  143.      * Passing 0 for conversion_flags gives all the default
  144.      * options.
  145.      */
  146.     bool convertFromImage( const QImage &img, int conversion_flags );
  147.     
  148.     /*
  149.      * This is an overloaded member function, provided for
  150.      * convenience. It differs from the above function only in
  151.      * what argument(s) it accepts.
  152.      */
  153.     bool convertFromImage( const QImage &img, ColorMode mode = WebColor );
  154.     
  155.     /**
  156.      * Loads a pixmap from the file fileName. Returns TRUE if
  157.      * successful, or FALSE if the pixmap could not be loaded. 
  158.      * 
  159.      * If format is specified, the loader attempts to read the
  160.      * pixmap using the specified format. If format is not
  161.      * specified (default), the loader reads a few bytes from the
  162.      * header to guess the file format.
  163.      *
  164.      * See the convertFromImage() documentation for a description
  165.      * of the conversion_flags argument.
  166.      *
  167.      * The QImageIO documentation lists the supported image
  168.      * formats and explains how to add extra formats.
  169.      */
  170.     bool load( const char *fileName, const char *format, int conversion_flags );
  171.     
  172.     /*
  173.      * This is an overloaded member function, provided for
  174.      * convenience. It differs from the above function only in
  175.      * what argument(s) it accepts.
  176.      */
  177.     bool load( const char *fileName, const char *format = 0,
  178.         ColorMode mode = WebColor );
  179.     /*
  180.      * Returns TRUE of the image is posessed of a color table that matches the
  181.      * Icon palette or FALSE otherwise.
  182.      * 
  183.      * An image with one color not found in the Icon
  184.      * palette is considered to make a match, since this extra color may be a
  185.      * transparent background.
  186.      */
  187.     bool checkColorTable(const QImage &image);    
  188. };
  189.  
  190. #endif
  191.  
  192.